const Admin = require("../models/Admin")
const md5 = require("md5")
//注册
exports.addAdmin = async function(adminObj){
    adminObj.userPwd = md5(adminObj.userPwd)
    const result = await Admin.findOne({
        where:{
            userName:adminObj.userName,
        }
      })
      if(result){
        return "用户名重复"
      }
    const ins = await Admin.create(adminObj)
    return "用户注册成功"//得到一个非常简单的对象
}

//登陆
exports.login = async function(adminObj){
    adminObj.userPwd = md5(adminObj.userPwd)
    const result = await Admin.findOne({
        where:{
            userName:adminObj.userName,
            userPwd:adminObj.userPwd
        }
      })
      if(result && result.userName === adminObj.userName && result.userPwd === adminObj.userPwd){
        return result;
      }else{
        return "用户名或密码输入错误"
      }
}

exports.getTx = async function(id){
  const result = await Admin.findOne({
      where:{
        id
      }
    })
    if(result){
      return result.userimg;
    }else{
      return "头像获取失败"
    }
}

exports.getYhm = async function(id){
  const result = await Admin.findOne({
      where:{
        id
      }
    })
    if(result){
      return result;
    }
}